#include "BootUi.h"
#include "ui_BootUi.h"
#include "WidgetHandler.h"
#include "BootSetting.h"
#include "LogoUtility.h"
#include "Mcu.h"
#include "App.h"
BootUi::BootUi(QWidget *parent) :
    BaseWidget(parent),
    ui(new Ui::BootUi)
{
    ui->setupUi(this);
    LogoUtility::getInstance()->addLogoLabel(ui->logo);
}

BootUi::~BootUi()
{
    delete ui;
}

void BootUi::activate()
{

}

void BootUi::inactivate()
{

}

void BootUi::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;

    default:
        break;
    }
}

void BootUi::on_enter_clicked()
{
    Mcu::getInstance()->touchSoundBeepMessage();
    RuntimeData::BootSetting::getInstance()->g_bootSettingInfo.isFirstTimeLogin = 1;
    RuntimeData::BootSetting::getInstance()->g_bootSettingInfo.languageIndex = ui->selectLanguage->currentIndex();
    RuntimeData::BootSetting::getInstance()->saveBootSettingInfoToRom();
    on_selectLanguage_currentIndexChanged(ui->selectLanguage->currentIndex());
    /* 跳转到登录界面 */
    WidgetHandler::getInstance()->displayWidget(LoginUi_Id);
}

void BootUi::on_selectLanguage_currentIndexChanged(int index) {

       lanindex = index;
       auto widget = WidgetHandler::getInstance()->getWidget(SystemSettingUi_Id);
       SystemSettingUi *swidget = dynamic_cast<SystemSettingUi*>(widget);
       if(swidget){
           qDebug()<<"find SystemSettingUi";
           swidget->modifyLanByindex(index);
       }
}
